package com.study.examples.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.study.examples.common.result.ResultCode;
import com.study.examples.common.result.ResultData;
import com.study.examples.dto.AddUserInfoRequest;
import com.study.examples.dto.AddUserInfoResponse;
import com.study.examples.dto.UserInfoListResponse;
import com.study.examples.model.UserInfo;
import com.study.examples.service.IUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: UserInfoController
 * @Description:
 * @author: limingxing
 * @Date: 2020-01-15 15:38
 */
@Api(value = "用户操作",tags = "用户信息操作API")
@RestController
public class UserInfoController {

    @Autowired
    private IUserInfoService userInfoService;

    @ApiOperation("添加用户")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public ResultData createBrand(@RequestBody AddUserInfoRequest request) {
        AddUserInfoResponse response = userInfoService.create(request);
        if (response.getCode().equals(ResultCode.SUCCESS.getCode())) {
            return ResultData.success(response);
        }
        return ResultData.success(response.getMsg());
    }

    @ApiOperation("获取列表")
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    public ResultData getList() {
        IPage<UserInfoListResponse> response = userInfoService.getList(1,3);

        return ResultData.success(response);
    }
}
